<?php
namespace Admin\Controller;
use Think\Controller;
class CaidanController extends Controller {
    public function caidan(){
    	$cd=D('Bill');
    	$count = $cd->count();
        $Page       = new \Think\Page($count,5);//继承
        $show       = $Page->show();//展示
        $list = $cd->limit($Page->firstRow.','.$Page->listRows)->select();
       
        $this->assign('count',$count);
        $this->assign('page',$show);
        $this->assign('list',$list);
        //var_dump($list);exit;

    	$this->display(); 
    }

    public function caiadd(){

           $cd=D('Bill');
           if(IS_POST){
             
            $data['veriety']=I('veriety');
    		$data['dishname']=I('dishname');
    		$data['price']=I('price');
    		$data['intor']=I('intor');
 	
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Upload/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();                                                                                                                                                                                                                     
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                $img_path1 = './Upload/'.$info['bill_big_logo']['savepath'];//图片的目录
                $img_path2 = $info['bill_big_logo']['savename'];//图片的名字

                $image = new \Think\Image();
                $image->open($img_path1.$img_path2);
                // 按照原图的比例生成一个最大为120*90的缩略图并保存为thumb.jpg

                $img_xiao = './Upload/thumb/'.$img_path2;
                $image->thumb(120, 90)->save($img_xiao);
                $data['bill_small_logo'] = $img_xiao;
                $data['bill_big_logo'] = $img_path1.$img_path2;
            }

            if(!$cd->create($data)){
                echo $cd->getError();
                exit;
            }else
            {	
                if($cd->add())
                {
                    $this->success('新增成功！',U('/admin/caidan/caidan',3));
                }else
                {
                    $this->error('新增失败！');
                }

            }
        }
        
        $this->display();
    



    }
}